package it.koutifaris.travianmap.ui;

import java.util.Iterator;

import junit.framework.Assert;

public class SquaredViewportBoundsIteratorTest extends AbstractSquaredViewportBoundsTest {

	private SquaredViewportBounds viewportBounds;
	private final int VIEW_PORT_SIZE = 45;
	private final int NUMBER_OF_EXPECTED_SQUARES_IN_VIEWPORT = VIEW_PORT_SIZE / SQUARE_SIZE + 2;

	@Override
	public void setUp() {
		viewportBounds = new SquaredViewportBounds(originCenteredViewState());
	}

	public void testXIterator() {
		Iterator<Integer> iterator = viewportBounds.xIterator(VIEW_PORT_SIZE);
		verifySquareCoordinates(VIEW_PORT_SIZE, iterator);
		verifyNoMoreElements(iterator);
	}

	public void testYIterator() {
		Iterator<Integer> iterator = viewportBounds.yIterator(VIEW_PORT_SIZE);
		verifySquareCoordinates(VIEW_PORT_SIZE, iterator);
		verifyNoMoreElements(iterator);
	}

	private void verifySquareCoordinates(int viewPortSize, Iterator<Integer> iterator) {
		for (int i = 0; i < NUMBER_OF_EXPECTED_SQUARES_IN_VIEWPORT; i++) {
			Assert.assertTrue(iterator.hasNext());
			Assert.assertEquals(Integer.valueOf(i), iterator.next());
		}
	}

	private void verifyNoMoreElements(Iterator<Integer> iterator) {
		Assert.assertFalse(iterator.hasNext());
	}
}
